--循知渐解
local xunzhijianjie = fk.CreateSkill {
    name = "mcdh_xunzhijianjie"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

xunzhijianjie:addEffect('active',{
    prompt = "#mcdh_xunzhijianjie-active",
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
    end,
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_num = 1,
    target_filter = function(self,player, to_select, selected)
        return #selected == 0 and to_select ~= player
    end,
    on_use = function(self, room, effect)
        local target = effect.tos[1]
        local player = effect.from
        room:obtainCard(
                target,
                player:getCardIds("h"),
                false,
                fk.ReasonPrey,
                player,
                self.name,
                nil,
                player
        )
        local cids = target:getCardIds("h")
        local choices, suits = {}, {}
        for _, cid in ipairs(cids) do
            local suit = Fk:getCardById(cid):getSuitString(true)
            if not suits[suit] then
                suits[suit] = {}
                table.insert(choices, suit)
            end
            table.insert(suits[suit], cid)
        end
        local chosen = room:askForChoice(
                target,
                choices,
                self.name,
                "#mcdh_xunzhijianjie-choice:" .. player.id
        )
        U.viewCards(player, lib.SortCardbySuit(cids), self.name, "#mcdh_xunzhijianjie-view:" .. target.id .. "::" .. chosen)
        room:obtainCard(
                player,
                suits[chosen],
                false,
                fk.ReasonPrey,
                target,
                self.name,
                nil,
                target
        )
    end,
})

Fk:loadTranslationTable {
    ["mcdh_xunzhijianjie"] = "循知渐解",
    [":mcdh_xunzhijianjie"] = "出牌阶段限一次，你可以将所有手牌交给一名其他角色，然后该角色向你展示手牌并将其中一种花色的所有牌交给你。",
    ["#mcdh_xunzhijianjie-active"] = "循知渐解:将所有手牌交给一名其他角色，其再将一些牌还给你",
    ["#mcdh_xunzhijianjie-choice"] = "循知渐解:将一种花色的所有手牌交给 %src",
    ["#mcdh_xunzhijianjie-view"] = "循知渐解:这是 %src 的手牌，他会将 %arg 牌交给你"
}

return xunzhijianjie